package xm.erzhan.controllers;

import xm.erzhan.models.UserEntity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class UserController {

    static private UserController userControllerIns;
    private List<UserEntity> userSet = null;

    public UserEntity getUserByUserName(String UserName) {
        UserEntity userEntity = null;


        UserEntity userItem = null;
        if (this.userSet != null) {
            Iterator<UserEntity> iterator = this.userSet.iterator();
            while (iterator.hasNext()) {

                userItem = iterator.next();
                if (userItem.getUserName().equals(UserName)) {
                    userEntity = userItem;
                    break;
                }
            }
        }


        return userEntity;
    }

    public void setUserSet(UserEntity user) {
        if (this.userSet == null) {
            this.userSet = new ArrayList<UserEntity>();
        }
        this.userSet.add(user);
    }

    static public UserController UserControllerShared() {
        if (userControllerIns == null) {
            userControllerIns = new UserController();
        }

        return userControllerIns;
    }
}
